package com.cn.customer.housekeeping.housekeepingb.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cn.customer.housekeeping.housekeepingb.R;
import com.cn.customer.housekeeping.housekeepingb.bean.ShopGridviewResp;

import java.util.List;


public class PopShopGridViewAdpter extends BaseAdapter {
    private Context context;
    private List<ShopGridviewResp> lists;

    public PopShopGridViewAdpter(Context context, List<ShopGridviewResp> lists) {
        this.context = context;
        this.lists = lists;
        for (int i=0; i<lists.size(); i++) {
            ShopGridviewResp info = new ShopGridviewResp();
            if (i ==0 ) {
                lists.get(i).setSelect(true);
            } else {
                lists.get(i).setSelect(false);
            }
        }

    }

    public void changeStatus(int select) {
        for (int i=0; i<lists.size(); i++) {
            lists.get(i).setSelect(false);
        }
        lists.get(select).setSelect(true);
    }


    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public ShopGridviewResp getItem(int arg0) {
        return lists.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_head_popshopgridview, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.item_name);
            holder.view5 = (ImageView) convertView.findViewById(R.id.view5);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (lists.get(position).isSelect()) {
            holder.view5.setVisibility(View.VISIBLE);
        }else {
            holder.view5.setVisibility(View.INVISIBLE);
        }


        holder.tv_name.setText(lists.get(position).getTitle());
        return convertView;
    }

    static class ViewHolder {
        private TextView tv_name;

        private    ImageView view5;
    }
}